#ifndef __VV_VERTEX_FACTORY_HPP__
#define __VV_VERTEX_FACTORY_HPP__

#include <set>
#include "vertex.hpp"

namespace vv {
  /** @brief The factory for generating verices and handling the vertex memory

      All vertices should be allocated through the vertex factory.

      @todo Enforce this as a singleton
      @todo Enforce that vertices are only allocated through this factory

      @note It's not clear why the fpair data members must be mutable
      and the assignment operator must be const.  It may be a bug in
      the g++ 3.4.3 implementation of std::remove_if().
   */
  class vertex_factory {
  public:
    virtual ~vertex_factory();

    vptr create_vertex();
    void collect_garbage();

    unsigned int count();

  protected:
    virtual abstract_vertex* allocate_vertex() = 0;

  private:
    typedef std::set<abstract_vertex*> vpool;
    typedef vpool::iterator            vpiter;

    void recurse_mark(abstract_vertex* v);

    vpool pool;
  };
}

#endif
